package com.dotndot.momserver.response;

import java.util.*;

import com.google.gson.*;

public class Response
{
    public enum Status
    {
        OK, ERROR, WARNING
    }

    public enum Code
    {
        S000, W001, // RET_EMAIL_UNAVAILABLE_FAIL
        W002, // RET_PASSWORD_UNAVAILABLE_FAIL
        E001, // RET_LOGIN_NOT_EXIST_EMAIL
        E002, // RET_LOGIN_DIFFERENT_PASSWORD
        E003
        // RET_JOIN_EMAIL_DUPLICATED
    }

    public enum Message
    {
        /* Common */
        RET_EMAIL_UNAVAILABLE, RET_PASSWORD_UNAVAILABLE,

        /* Version */
        RET_VERSION_SUCCESS,

        /* Login */
        RET_LOGIN_SUCCESS, RET_LOGIN_NOT_EXIST_EMAIL, RET_LOGIN_DIFFERENT_PASSWORD,

        /* Join */
        RET_JOIN_SUCCESS, RET_JOIN_EMAIL_DUPLICATED,

        /* Baby */
        RET_BABY_ADD_SUCCESS,
        RET_BABY_LIST_SUCCESS,
        RET_BABY_LIST_FAIL,
        
        /* Story */
        RET_STORY_ADD_ITEM_SUCCESS,
        RET_STORY_GET_LIST_SUCCESS,
        RET_STORY_GET_LIST_END,
        RET_STORY_GET_LIST_FAIL,
        
        /* Diary */
        RET_DIARY_ADD_ITEM_SUCCESS,
        RET_DIARY_LIST_SUCCESS,
        
    }

    private Status status;
    private Code code;
    private Message message;
    private Object object;
    private List<Object> list;
//    private List<ResBaby> babyList;
    private Collection<Object> collection = null;
    
    public Response( Status status, Code code, Message message )
    {
        this.status = status;
        this.code = code;
        this.message = message;
    }

    public Response( Status status, Code code, Message message, Object object )
    {
        this.status = status;
        this.code = code;
        this.message = message;
        this.object = object;
    }
    
    public Response( Status status, Code code, Message message, List<Object> list )
    {
        this.status = status;
        this.code = code;
        this.message = message;
        this.list = list;
    }

    public String toJson()
    {
        Gson gson = new Gson();
        if(collection == null){
            collection = new ArrayList<Object>();
        }
        collection.add(this.status);
        collection.add(this.code);
        collection.add(this.message);
        if(this.object != null){
            collection.add(this.object);        
        }
        if(this.list != null){
            collection.add(this.list);
        }
        String json = gson.toJson(collection);
        return json;
    }

//    public static Response constructFromJson( String json )
//    {
//        Gson gson = new Gson();
//        return gson.fromJson(json, Response.class);
//    }
}
